/*
 * KIMWONSORK@GMAIL.COM
 * COPYRIGHT CRAYONSOFT All rights reserved.
 * 2013오후 9:07:00
 * kws
 */

package com.crayon.account.fragments.ui;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.crayon.account.impl.OnDateChangeListener;
import com.crayon.sharemenu.R;
import com.crayon.util.UIBIND;
import com.crayon.util.UTILDate;

import java.util.Date;

/**
 * com.crayon.account.fragments.FragmentSegmentButtom
 * @author kws
 *
 */
public class FragmentDateMove extends Fragment
implements OnClickListener
{

	Date mDate = new Date();
	OnDateChangeListener onDateChangeListener;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View rootView = inflater.inflate(R.layout.fragment_date_segment,container, false);
		
		return rootView;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		UIBIND.bindView(getView(), R.id.buttonMonthPrev, this);
		UIBIND.bindView(getView(), R.id.buttonMonthNext, this);
		UIBIND.bindView(getView(), R.id.buttonDateView, this);
		UIBIND.bindView(getView(), R.id.buttonMonthToday,this);
		UIBIND.bindButton(getView(), R.id.buttonDateView, UTILDate.getYYYYMM(mDate));

		super.onActivityCreated(savedInstanceState);
	}

	
	public OnDateChangeListener getOnDateChangeListener() {
		return onDateChangeListener;
	}

	public void setOnDateChangeListener(OnDateChangeListener onDateChangeListener) {
		this.onDateChangeListener = onDateChangeListener;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId()){
		case R.id.buttonMonthPrev:
			mDate = UTILDate.getNextMONTH(mDate, -1);
			UIBIND.bindButton(getView(), R.id.buttonDateView, UTILDate.getYYYYMM(mDate));
			if(getOnDateChangeListener()!=null){
				getOnDateChangeListener().OnDateChange(mDate, mDate);
			}
			break;
		case R.id.buttonMonthNext:

			mDate = UTILDate.getNextMONTH(mDate, 1);
			UIBIND.bindButton(getView(), R.id.buttonDateView, UTILDate.getYYYYMM(mDate));
			if(getOnDateChangeListener()!=null){
				getOnDateChangeListener().OnDateChange(mDate, mDate);
			}
			break;
		case R.id.buttonDateView:
			break;
		case R.id.buttonMonthToday:
			mDate.setTime(System.currentTimeMillis());;
			UIBIND.bindButton(getView(), R.id.buttonDateView, UTILDate.getYYYYMM(mDate));
			if(getOnDateChangeListener()!=null){
				getOnDateChangeListener().OnDateChange(mDate, mDate);
			}
			break;

		}

	}

	public Date getmDate() {
		return mDate;
	}

	public void setmDate(Date mDate) {
		this.mDate = mDate;
	}


	

}
